package cn.itcast.order;

import cn.itcase.feign.client.UserClient;
import cn.itcase.feign.config.FeignConfiguration;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
//定义的FeginClient不在SpringBootApplication的扫描宝范围内的时候，这些Client无法使用，可以在EnableFeignClients注解中指定basePackages
//或者使用如下的方式，直接指定clients  指定字节码文件  推荐
@EnableFeignClients(defaultConfiguration = FeignConfiguration.class,clients = {UserClient.class})
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }


    /**
     * 创建RestTemplate并注入容器
     * @return
     */
    @Bean
    @LoadBalanced //开启负载均衡
    public RestTemplate restTemplate(){
        return  new RestTemplate();
    }

//    @Bean
//    public IRule randomRule() {
//        return  new RandomRule();
//    }
}